package cn.dengta.webapp.im.enums;

import java.util.Set;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import com.google.common.collect.ImmutableSet;
import lombok.Getter;

/**
 * 云信自定义消息通知全局code码
 */
@Getter
public enum CustomMsgType implements ValueProxyImpl<CustomMsgType, Integer> {

	/** 自定义通知相关code码 */
	LESS_COIN(400, "余额不足"),

	/** 4.0.0 版 钻石用户 */
	FIRST_COIN(401, "首次钻石聊天弹窗"),

	DIAL(600, "发起通话"),
	QUIT(601, "挂断通话"),

	RECORD_VIDEO(700, "录制视频牵线"),

	/** 聊天通话违规 */
	VIOLATION(750, "聊天违规提示"),

	/* 自定义消息相关code码 */
	GIFT(800, "礼物消息"),
	GREET(801, "搭讪消息"),
	QUESTION(810, "问题消息", true),
	ANSWER(811, "回答消息", true),

	/** 阅后即焚的图片 */
	DISPOSABLE_IMAGE(812, "一次性图片"),

	RED_PACKET(888, "红包消息"),
	RED_PACKET_RECEIVE(889, "红包领取"),
	RED_PACKET_USER(890, "个人红包消息"),

	GROUP_INVITE(1000, "群邀请"),
	GROUP_ANNOUNCEMENT(1001, "群公告"),

	GROUP_VIP(1100, "群VIP到期通知"),
	LIKE_ONLINE_NOTICE(1200, "喜欢在线通知"),

	CARD(1300, "卡片消息"),
	LIVE_SHARE(1301, "直播间分享"),
	GAME_SHARE(1400, "游戏分享"),

	/** 心愿单 */
	WISH_LOG(1420, "心愿表单数据"),
	/** 心愿单完成提示 */
	WISH_COMPLETE_TITLE(1422, "心愿单完成提示"),

	LIVE_QUIT(3000, "直播关闭"),
	LIVE_MIC_USER(3001, "直播连麦"), // 建立连麦连接，准备推流
	LIVE_START_MIC(3002, "直播连麦开始"), // 推流成功，连麦已开始
	LIVE_USER_MIC_APPLY(3003, "用户申请连麦"),
	LIVE_ANCHOR_MIC_REJECT(3004, "主播拒绝用户申请连麦"),
	LIVE_USER_MIC_NO_RESPONSE(3005, "观众连麦无响应"),
	LIVE_USER_MIC_REJECT(3006, "观众拒绝连麦"),
	LIVE_USER_KICK(3007, "直播间踢人"),
	LIVE_USER_BLACK(3008, "直播间拉黑"),
	LIVE_END_MIC(3009, "直播连麦结束"), // 结束连麦
	LIVE_USER_FROZEN(3010, "封禁直播"),
	LIVE_MIXED_FLOW(3011, "直播连麦混流"),
	LIVE_ANCHOR_REJECT_USER_APPLY(3012, "主播取消观众连麦申请"),
	LIVE_FOLLOW_MSG(3013, "聊天室关注提示"),
	LIVE_DIG_MSG(3014, "直播点赞"),
	LIVE_MIXED_FLOW_END(3019, "直播连麦混流结束"),

	LIVE_ON_NOTIFY(3200, "直播开播通知"),

	LIVE_SYNC(3333, "直播间数据状态同步"),

	/** pk邀请 */
	LIVE_PK_INVITE(3500, "PK邀请"),
	/** 接受PK,开始PK */
	LIVE_PK_ON(3501, "接受PK邀请,开始PK"),
	/** PK中的数据视图 */
	LIVE_PK_DATA(3502, "PK中的数据视图"),
	/** PK中的结果数据 */
	LIVE_PK_RESULT(3503, "PK结束，PK结果数据"),
	/** PK拒绝邀请 */
	LIVE_PK_CANCEL(3504, "PK拒绝邀请"),
	/** 对方将你拉入了PK黑名单，我方/对方获胜（平局） */
	LIVE_PK_ING_BLACKLIST(3505, "对方将你拉入了PK黑名单，我方/对方获胜（平局） "),
	/** 未匹配的合适的主播 */
	LIVE_PK_MATCH_FAIL(3506, "未匹配的合适的主播"),
	/** 关闭PK混流 */
	LIVE_PK_CLOSE_MIX(3507, "关闭PK混流"),
	/** 直播间中断 */
	LIVE_PK_INTERRUPT(3508, "直播间中断"),
	/** PK拒绝邀请 */
	LIVE_PK_NO_RESPONSE(3509, "PK邀请无响应"),
	/** Ai 速配 */
	AI_SPEED_MSG(3600, "AI速配消息"),

	LIVE_SEND_GIFT(20002, "直播间赠送礼物"),

	//
	;

	public final Integer value;
	public final boolean costRequired;
	final ValueProxy<CustomMsgType, Integer> proxy;

	CustomMsgType(Integer value, String label, boolean costRequired) {
		this.value = value;
		this.costRequired = costRequired;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	CustomMsgType(Integer value, String label) {
		this(value, label, false);
	}

	public static final CustomMsgType[] CACHE = values();

	public static boolean needPayment(Integer value) {
		CustomMsgType type = CustomMsgType.of(value);
		return type != null && type.costRequired;
	}

	public static CustomMsgType of(Integer value) {
		return DIAL.getValueOf(value);
	}

	/** APP端自定义的【免费】消息类型 */
	public static Set<Integer> freeAppCustomTypes = Set.of(
			GAME_SHARE.value,
			LIVE_SHARE.value // APP端自定义的【分享直播间卡片】消息类型
	);

	static Set<Integer> appCustomTypes = ImmutableSet.<Integer>builder()
			.addAll(freeAppCustomTypes)
			.add(DISPOSABLE_IMAGE.value)
			.build();

	/** APP端自定义的自定义消息类型（含免费） */
	public static Set<Integer> appCustomTypes() {
		return appCustomTypes;
	}

}
